/*
 * tabview.js 是基于javer.js的插件
 * 对动态tab页提供支持
 * 通过$.extend进行扩展
 */
$.extend({
	/*
	 * 将一个字符串映射成Map对象
	 * @param {Object} mapstring "key1-val1,key2-val2,key3-val3...."
	 */
	map: function(mapstring) {
		mapstring = mapstring || "";
		var keyvals = mapstring.split(","), map = {};
		for (var id in keyvals) {
			var kvs = keyvals[id].split("-");
			map[kvs[0]] = kvs[1];
		}
		return map;
	},
	tabView: function(viewIds) {
		var map = $.map(viewIds);
		for (var key in map) {
			$(key).get().onmouseover = function() {
				if (this.className == "selectLi") {
					return;
				}
				var me = this,
				timer = setTimeout(function() {
					for (var prop in map) {
						$(prop).style("noSelectLi");
						$(map[prop]).hide();
					}
					me.className="selectLi";
					$(map[me.id]).display();
				}, 100);
				
				me.onmouseout = function() {
					clearTimeout(timer);
					timer = undefined; // stop memory leak
				}
			};
		}
	}
});
